<?php
/**
 * Created by PhpStorm.
 * User: yu
 * Date: 2017/1/11
 * Time: 下午4:02
 */

namespace Home\Controller;


use Common\Controller\HomeController;
use Common\Model\AddressModel;

class AddressController extends HomeController
{
	protected $model;
	public function __init(){
		$this->model = new AddressModel();
	}
	public function add ()
	{
		//模拟已经登录了
		$_SESSION['user'] = [
			'uid'=>1,
			'uname'=>'yuonly'
		];
		//地址表数据
		$data = [
			'uaname'   => I( 'post.uaname' ) ,
			'province' => $_POST[ 'address' ][ 0 ] ,
			'city'     => $_POST[ 'address' ][ 1 ] ,
			'block'    => $_POST[ 'address' ][ 2 ] ,
			'detail'=>I('post.detail'),
			'code'=>I('post.code'),
			'phone'=>I('post.phone'),
			'uid'=>$_SESSION['user']['uid']
		];
		$re = (new AddressModel())->store($data);
		redirect(u('home/order/lists'));
	}

	/**
	 * 订单页面异步修改 默认地址方法
	 */
	public function setDefault(){
		$uaid = I('post.uaid');
		$this->model->where("uaid<>$uaid")->setField('status',0);
		$this->model->where("uaid=$uaid")->setField('status',1);
	}
}